import 'package:flutter/material.dart';
import 'package:vdrag_saas/bus.dart';

class TypeLink extends StatefulWidget {
  String text;
  bool selected;
  Function(TypeLinkState target) callback;
  TypeLink(this.text, {super.key, this.selected = false, required this.callback});
  @override
  State<StatefulWidget> createState() => TypeLinkState();
}

class TypeLinkState extends State<TypeLink> {
  late String text;
  @override
  void initState() {
    text = widget.text;
    // TODO: implement initState
    if (widget.text == '全部') {
      Global.defaultType = this;
    }
  }
  void searchByType() {
    widget.callback(this);
  }
  void select() {
    print(text);
    setState(() {
      widget.selected = true;
    });
  }
  void unselect() {
    setState(() {
      widget.selected = false;
    });
  }
  @override
  Widget build(BuildContext context) {
    return TextButton(
      onPressed: searchByType,
      style: const ButtonStyle(
        overlayColor: MaterialStatePropertyAll(Colors.transparent)
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Text(
            widget.text,
            style: TextStyle(
              fontSize: 14,
              color: widget.selected
                  ? const Color(0xff409EFF)
                  : const Color(0xff666666),
            ),
          ),
          Container(
            color: widget.selected? const Color(0xff409EFF) : const Color(0xfff9f9f9),
            height: 2,
            width: 14.0 * widget.text.length
          )
        ],
      ),
    );
  }
}
